package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.mapper.UmsRoleMapper;
import com.mall.domain.UmsRole;
import com.mall.interface1.api.UmsRoleApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@DubboService
public class UmsRoleAPiImpl implements UmsRoleApi {
    @Autowired
    private UmsRoleMapper umsRoleMapper;

    @Override
    public void save(UmsRole role) {
        if(role.getCreateTime() == null){
            role.setCreateTime(LocalDateTime.now());
        }
        umsRoleMapper.insert(role);
    }

    @Override
    public void deleteIds(Integer[] ids) {
        umsRoleMapper.deleteBatchIds(Arrays.asList(ids));
    }

    @Override
    public IPage<UmsRole> page(String keyword, Integer pageNum, Integer pageSize) {
        IPage<UmsRole> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<UmsRole> q = new LambdaQueryWrapper<>();
        if(keyword!=null&& !keyword.equals("")){
            q.like(UmsRole::getName,keyword);
        }
        return umsRoleMapper.selectPage(page,q);
    }

    @Override
    public List<UmsRole> findAll() {
        return umsRoleMapper.selectList(null);
    }

    @Override
    public void update(UmsRole role) {
        umsRoleMapper.updateById(role);
    }

    @Override
    public UmsRole findById(Integer id) {
        return umsRoleMapper.selectById(id);
    }

    @Override
    public List<UmsRole> queryId(List<Long> roleIds) {
        LambdaQueryWrapper<UmsRole> qw = new LambdaQueryWrapper<>();
        qw.in(UmsRole::getId,roleIds);
      return   umsRoleMapper.selectList(qw);
    }
}
